<template>
    <div id='' class='system_set_form'>
        <i-form ref="iFormRef" v-if="isShow" :config="isAdd ? addConfig : editConfig">
            <!-- <template #tenantName="{row}">
                <Cascader filterable clearable change-on-select :data="xzqList" v-model="xzq" />
            </template> -->
        </i-form>
    </div>
</template>
<script>
import { addConfig, editConfig } from './form_config'
export default {
    name: '',
    props: [''],
    data() {
        this.addConfig = icu.util.deepClone(addConfig);
        this.editConfig = icu.util.deepClone(editConfig);
        return {
            isShow: false,
            isAdd: true,
            addConfig: this.addConfig,
            editConfig: this.editConfig,
            formData: {},
            // xzq: [],
            // xzqList: [],
        };
    },
    components: {},
    computed: {},
    beforeMount() { },
    mounted() {
        this['$api'] = this.$Api.get(['systemSetup:systemManger']);
    },
    methods: {
        getForm(cb) {
            this.$refs.iFormRef.submit('userAddUpdata', (fromRes) => {
                this.formData = fromRes;
                if (cb) {
                    cb(this.formData)
                }
            })
        },
        isAddOrEdit(flag) {
            this.isAdd = flag;
            this.getSelect();
            this.getXzqList();
            this.isShow = true;
        },
        setData(row) {
            this.$nextTick(() => {
                row.tenantCode = row.tenantCodeValues.split(',')
                this.$refs.iFormRef.setData(row);
            })
        },
        // 获取行政区数据
        getXzqList() {
            // return new Promise((resolve, reject) => {
            this.$http.$get('tenantUserRoleRegionTree', { params: {} }).then(res => {
                if (res.code == 200) {
                    // resolve(res.data)
                    let config = this.isAdd ? 'addConfig' : 'editConfig'
                    let index = this[config].form.findIndex(item => item.key == 'tenantCode');
                    this[config].form[index].option = res.data;
                    return
                }
                this.$Message.error(res.msg)
            })
            // })
        },
        // 获取角色配置
        getSelect() {
            // return new Promise((resolve, reject) => {
            this.$api.roleList({ tenant: 1 }, data => {
                let config = this.isAdd ? 'addConfig' : 'editConfig'
                let index = this[config].form.findIndex(item => item.key == 'roleIds');
                this[config].form[index].option = data;
                // resolve(this[config].form[index].option)
                // })
            })
        }
    },
    watch: {}
}
</script>
<style lang='less' scoped>
</style>
